package bravo.xc.com.xc_bravo_android.operation.person_center;

import android.content.Context;

import bravo.xc.com.xc_bravo_android.beans.SendCodeBeans;
import bravo.xc.com.xc_bravo_android.beans.SendMoneyCodeResultBeans;
import bravo.xc.com.xc_bravo_android.http.HttpSingleton;
import bravo.xc.com.xc_bravo_android.http.UserOperationService;
import cn.jpush.android.api.JPushInterface;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static bravo.xc.com.xc_bravo_android.beans.AliaBeans.LOGINOUT;
import static bravo.xc.com.xc_bravo_android.beans.AliaBeans.LOGINOUTREAL;

/**
 * CREATED BY YANK
 * DATE : 2017/10/28
 * MAIL : YANK.TENYOND@GMAIL.COM
 * FUNCTION :
 */

public class PersonalCenterPresenter extends PersonalCenterContract.PersonalCenterPresenter {

    private UserOperationService userOperationService = HttpSingleton.getInstance().service;

    @Override
    public void logout(SendCodeBeans sendCodeBeans, final Context contexts) {

        compositeSubscription.add(userOperationService.logout(sendCodeBeans)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<SendMoneyCodeResultBeans>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        view.showProgress(false);
                        JPushInterface.setAlias(contexts,LOGINOUTREAL,context.getSharedPreferences("username", Context.MODE_PRIVATE).getString("username",null));
                    }

                    @Override
                    public void onNext(SendMoneyCodeResultBeans sendMoneyCodeResultBeans) {
                        view.removeUserInfo();
                        view.toNewActivity(0);
                        view.showProgress(false);
                    }
                })
        );
    }
}
